package com.gdut.simple.presenter.user;

import com.gdut.simple.common.RequestCallback;
import com.gdut.simple.contract.UpdateProfileContract;
import com.gdut.simple.model.IUpdateProfileModel;
import com.gdut.simple.model.impl.UpdateProfileModelImpl;

public class UpdateProfilePresenter implements UpdateProfileContract.Presenter {

    private UpdateProfileContract.View mView;
    private IUpdateProfileModel mUpdateProfileModel;

    public UpdateProfilePresenter(UpdateProfileContract.View view) {
        this.mView = view;
        mUpdateProfileModel = new UpdateProfileModelImpl();
        mView.setPresenter(this);
    }

    @Override
    public void update() {
        if (!mView.isLogin()) {
            return;
        }
        mView.showProgress("修改中...");
        mUpdateProfileModel.update(mView.getImagePath(), new RequestCallback<String>() {
            @Override
            public void onSuccess(String s) {
                mView.hideProgress();
                mView.showMessage("修改成功");
                mView.next();
            }

            @Override
            public void onFailure(String message) {
                mView.hideProgress();
                mView.showMessage(message);
            }
        });
    }
}
